package com.oneday.ashop.console.base.web;

import com.oneday.ashop.console.authority.AuthService;
import com.oneday.ashop.console.base.shiro.filter.BaseResourceFilter;
import com.oneday.ashop.core.base.util.CollectionUtil;
import com.oneday.ashop.core.entity.Resource;
import com.oneday.ashop.core.entity.Role;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.ContextLoaderListener;
import org.springframework.web.context.support.WebApplicationContextUtils;

import javax.servlet.ServletContextEvent;
import java.util.*;

/**
 * 重写ContextLoaderListener类，用于加载数据库数据到缓存
 * User:bob.yang
 * Date 2015/8/6 0006
 */
@Slf4j
public class MyContextLoaderListener extends ContextLoaderListener {

//    //路径和资源的映射
//    public static Map<String, Resource> resourceMap = new HashMap<>();
//
//    //资源和角色的映射
//    public static Map<Integer, Set<String>> resourceAndRolesMap = new HashMap<>();
//
//    @Autowired
//    private AuthService authService;

    @Autowired
    private BaseResourceFilter baseResourceFilter;


    public void contextInitialized(ServletContextEvent event) {
//        log.info("初始化资源过滤器...");
//        List<Resource> resources = authService.getALlResources();
//        for(Resource resource : resources) {
//            resourceMap.put(resource.getUrl(), resource);
//        }
//        log.info("初始化资源过滤器完成！");
//        baseResourceFilter.init();
    }


}
